package samse.exam.test1;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;

public class PageChangerActivity extends Activity {
		
	private static final String TAG = "PageChangerActivity";
	private PageChanger mPc=null;
	
	private Bitmap page1;
	private Bitmap page2;
	private Bitmap page3;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.page_changer);
		
		mPc = (PageChanger)findViewById(R.id.page_changer);
		
		page1 = BitmapFactory.decodeResource(getResources(), R.drawable.page1);
		page2 = BitmapFactory.decodeResource(getResources(), R.drawable.page2);
		page3 = BitmapFactory.decodeResource(getResources(), R.drawable.page3);
		
		mPc.setBitmap(page1, page2);
		mPc.setGrip(BitmapFactory.decodeResource(getResources(), R.drawable.move_page),
				BitmapFactory.decodeResource(getResources(), R.drawable.move_page2));
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case R.id.goto_prev_page:
			mPc.onShotPage(PageChanger.DIRECTION_PREV);
			mPc.invalidate();
			return true;
		case R.id.goto_next_page:
			mPc.onShotPage(PageChanger.DIRECTION_NEXT);
			mPc.invalidate();
			return true;
		}
		return false;
	}

	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {
		menu.removeGroup(Menu.NONE);
		getMenuInflater().inflate(R.menu.menu, menu);
		return true;
		//return super.onPrepareOptionsMenu(menu);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		Log.d(TAG, "onTouchEvent --> " + event);
		mPc.onTouchEvent(event);
		return super.onTouchEvent(event);
	}
	
	
}
